using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UVRect : MonoBehaviour
{
    public GameObject vertexPrefab;
    public List<GameObject> childs = new List<GameObject>();
    private RectTransform recttf;
    public float scale = 0.2f;
    private void Awake()
    {
        recttf = GetComponent<RectTransform>();
    }

    public void Done()
    {
        gameObject.SetActive(true);
        transform.localScale = Vector3.one*scale;
    }

    public void Add(List<Vector3> ls, List<object> _names)
    {
        for (int i = 0; i < ls.Count; i++)
        {
            Add(ls[i], _names[i]);
        }
    }

    public void Add(Vector3 localpos, object _name)
    {
        GameObject go = null;
        go = GameObject.Instantiate(vertexPrefab);
        childs.Add(go);
        var tf = go.transform;
        tf.SetParent(transform);
        go.name = _name.ToString();
        go.SetActive(true);
        tf.GetComponent<RectTransform>().anchoredPosition = localpos;
        tf.localScale = Vector3.one;
    }


    private void OnDisable()
    {
        for (int i = 0; i < childs.Count; i++)
        {
            GameObject.Destroy(childs[i]);
        }

        childs.Clear();
        recttf.sizeDelta += new Vector2(100, 100);
    }
}